home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / newmk.zip / LIB / MYOPT.C < prev   
C/C++ Source or Header  |  1992-07-13  |  1KB  |  47 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4. #include "myopt.h"
  5. #define TRUE 1
  6. #define FALSE 0
  7.  
  8. char *p_optstr;
  9.  
  10. int my_getopt(int argc, char *argv[], char *optstring)
  11. {
  12.     static index = 1;
  13.     char ch;
  14.     char *pch = NULL;
  15.  
  16.     p_optstr = NULL;
  17.  
  18.     if ( ! (index < argc) )
  19.         return(0);
  20.  
  21.     if (argv[index][0] == '-'
  22.         && isalnum(ch = argv[index][1]))
  23.         {
  24.         if (pch = strchr( optstring, ch))
  25.             {
  26.             // We have an option flag.
  27.             // Does it have an arguement?
  28.             if (*(pch + 1) == ':'
  29.                 && index < argc -1)
  30.                 {
  31.                 // We have an arguement.
  32.                 p_optstr = argv[index+1];
  33.                 index += 2;
  34.                 return((int) ch);
  35.                 }
  36.             else
  37.                 {
  38.                 index++;
  39.                 return((int) ch);
  40.                 }
  41.             }
  42.         }
  43.     p_optstr = argv[index];
  44.     index++;
  45.     return(-1);
  46. }
  47.